/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hanuma;

import java.util.*;
import java.io.*;
import com.google.gson.*;

/**
 *
 * @author niyaz
 */
public class FileStoredPersonWriter {

    BufferedWriter writer;
      Gson gson = new Gson();

    public FileStoredPersonWriter(String file) throws Exception {
        try {
            writer = new BufferedWriter(new FileWriter(new File(file)),100000);
        } catch (Exception e) {
            throw new Exception("can't open file for writing to write user info");
        }
    }
    public void add(Person person) throws Exception {

        person.cleanBeforeSerilazation();
        String json = gson.toJson(person);
        writer.write(json+"\n");
    }
    public void close() throws Exception{
        writer.close();
    }
}
